package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.ydkj.a37e_mall.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/14.
 * 待申报商品
 */

public class StaydeclareCommActivity extends Activity {
    private Activity mActivity;
    private ImageView img_back;
    private TextView tv_staydeclare_comm;
    private PullToRefreshListView ref_staydeclare_comm;
    private StaydeclareCommAdpater staydeclareCommAdpater;
    private List<String> list;
    private boolean is_edit = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.staydeclare_comm);
        mActivity = this;
        init();
    }

    private void init() {
        img_back = (ImageView) mActivity.findViewById(R.id.img_back);
        tv_staydeclare_comm = (TextView) mActivity.findViewById(R.id.tv_staydeclare_comm);

        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        list = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            list.add("111" + i);
        }
        ref_staydeclare_comm = (PullToRefreshListView) mActivity.findViewById(R.id.ref_staydeclare_comm);
        staydeclareCommAdpater = new StaydeclareCommAdpater(list);
        ref_staydeclare_comm.setAdapter(staydeclareCommAdpater);

        ref_staydeclare_comm.setOnRefreshListener2(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {

            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {

            }
        });
    }

    private class StaydeclareCommAdpater extends BaseAdapter {
        private List<String> list;

        private StaydeclareCommAdpater(List<String> info) {
            if (info == null) {
                info = new ArrayList<>();
            }
            list = info;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup viewGroup) {
            ViewHolder vh = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.staydeclare_comm_list, null);
                vh = new ViewHolder();
                vh.rly_general = (RelativeLayout) convertView.findViewById(R.id.rly_general);
                vh.cb_staydeclare_comm_all = (CheckBox) convertView.findViewById(R.id.cb_staydeclare_comm_all);
                vh.cb_staydeclare_comm_single = (CheckBox) convertView.findViewById(R.id.cb_staydeclare_comm_single);
                vh.tv_staydeclare_comm_edit = (TextView) convertView.findViewById(R.id.tv_staydeclare_comm_edit);
                vh.tv_staydeclare_name = (TextView) convertView.findViewById(R.id.tv_staydeclare_name);
                vh.tv_staydeclare_price = (TextView) convertView.findViewById(R.id.tv_staydeclare_price);
                vh.tv_staydeclare_postage = (TextView) convertView.findViewById(R.id.tv_staydeclare_postage);
                vh.tv_staydeclare_color = (TextView) convertView.findViewById(R.id.tv_staydeclare_color);
                vh.tv_staydeclare_size = (TextView) convertView.findViewById(R.id.tv_staydeclare_size);
                vh.tv_staydeclare_less = (TextView) convertView.findViewById(R.id.tv_staydeclare_less);
                vh.tv_staydeclare_add = (TextView) convertView.findViewById(R.id.tv_staydeclare_add);
            } else {
                vh = (ViewHolder) convertView.getTag();
            }
            convertView.setTag(vh);
            if (position == 0) {
                vh.rly_general.setVisibility(View.VISIBLE);
            }
            //编辑
            final ViewHolder finalVh = vh;
            vh.tv_staydeclare_comm_edit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Log.e("ssss", "编辑");
                    if (is_edit == false) {
                        finalVh.tv_staydeclare_comm_edit.setText("编辑");
                        tv_staydeclare_comm.setText("申报");
                        is_edit = true;
                    } else {
                        finalVh.tv_staydeclare_comm_edit.setText("完成");
                        tv_staydeclare_comm.setText("删除");

                        is_edit = false;
                    }
                }
            });

            return convertView;
        }

        private class ViewHolder {
            private RelativeLayout rly_general;
            private CheckBox cb_staydeclare_comm_all, cb_staydeclare_comm_single;
            private TextView tv_staydeclare_comm_edit, tv_staydeclare_name, tv_staydeclare_price, tv_staydeclare_postage, tv_staydeclare_color, tv_staydeclare_size, tv_staydeclare_less, tv_staydeclare_add;
            private EditText et_staydeclare_number;

        }
    }
}
